/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.agh.air.bpel2bpmn.comparator.impl;

import org.agh.air.bpel2bpmn.comparator.AbstractComparator;
import org.agh.air.bpel2bpmn.exception.PatternNotFoundException;
import org.w3c.dom.Node;

/**
 *
 * @author paletz
 */
public class SimpleMergeComparator extends AbstractComparator{
    
   /*   <sequence>
            <switch name="Gateway-13103">
                <case condition="">
                    <invoke name="Task-13128" partnerLink="" portType="" operation="" inputVariable="" outputVariable=""/>

                </case>
                <case condition="">
                    <invoke name="Task-13131" partnerLink="" portType="" operation="" inputVariable="" outputVariable=""/>

                </case>
            </switch>
            <invoke name="Task-13134" partnerLink="" portType="" operation="" inputVariable="" outputVariable=""/>

        </sequence>
   */

    @Override
    public String compare(Node node) throws PatternNotFoundException {
        if(node.getNodeName().equals(SEQUENCE)) {
           if(getFirstChild(node).getNodeName().startsWith(SWITCH)){
                
                if(getSecondChild(node).getNodeName().equals(INVOKE))
                    return getFirstChild(node).getNodeName().replaceFirst(SWITCH, SIMPLE_MERGE + LTMP) + "."+ getNameAttribute(getSecondChild(node)) + RTMP;
                else
                    return getFirstChild(node).getNodeName().replaceFirst(SWITCH, SIMPLE_MERGE + LTMP) + "."+ getSecondChild(node).getNodeName() + RTMP;
            }
        }
            
        
        throw new PatternNotFoundException();
    }
    
}
